import React from 'react'
import { connect } from 'dva'
import { Card, Table, Spin,List } from 'antd'


/**
 * ResearchList 
 */
class ResearchList extends React.Component {
    state = {
        data: this.props.data,
    }
    componentDidMount() {
        this.fetchData(this.props)
    }
    componentWillReceiveProps(nextProps) {

        if ((nextProps.type !== this.props.type)) {
            this.fetchData(nextProps)
        }
        if (nextProps.data !== this.props.data) {
            this.setState({
                data: nextProps.data,
            })
        }
    }
    fetchData = (props) => {
        this.setState({
            data: {},
        })
        if(props.type){
            eval(`
            props.dispatch({
                type: 'researchReport/get${props.type}',
                payload:props
            })
            `)
        }
    }
    viewDetails=(id)=>{
        this.props.dispatch({
            type: `app/changeRouter`,
            payload:{
                pathname:'/customerService/researchReportDetail',
                query:{
                    id,
                    at:Date.parse(new Date())/1000
                }
            }
          })
    }

    render() {
        const {field,list}=this.state.data;
        let dataSource=list||[];
        return (
            <Card className="tableCard researchList">
                <List
										 size="large"
										 bordered
										 dataSource={dataSource}
										 renderItem={item => (
										   <List.Item>
											 <List.Item.Meta
											   title={<a onClick={() => this.viewDetails(item.TEXTTITLE)}>{item.TEXTTITLE}</a>}
											 />
										   </List.Item>
										 )}
									   />
            </Card>
        )

    }
}

ResearchList.defaultProps = {
    keywords: '',
    data: {

    }
}

export default connect()(ResearchList)
